package com.ld.control.business.user.controller;

import com.ld.control.business.user.service.MenuService;
import com.ld.control.business.user.vo.req.MenuReqVo;
import com.ld.control.business.user.vo.resp.MenuRespVo;
import com.ld.control.business.user.vo.resp.MenuTreeRespVo;
import com.ld.control.common.vo.GenerateListVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "菜单相关接口")
@RestController
public class MenuController {

    @Autowired
    private MenuService menuService;

    @PostMapping("/api/centralControl/menu/add")
    @Operation(summary = "添加菜单信息")
    public ResultResponse<ResultResponseEnum> add(@RequestBody MenuReqVo reqVo) {
        menuService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/menu/update")
    @Operation(summary = "修改菜单信息")
    public ResultResponse<ResultResponseEnum> update(@RequestBody MenuReqVo reqVo) {
        menuService.update(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/menu/delete")
    @Operation(summary = "删除菜单信息")
    public ResultResponse<ResultResponseEnum> delete(@RequestParam Long id) {
        menuService.deleteById(id);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/menu/getById")
    @Operation(summary = "查询菜单详情")
    public ResultResponse<MenuRespVo> getById(@RequestParam Long id) {
        MenuRespVo menuRespVo = menuService.getById(id);
        return ResultResponse.success(menuRespVo);
    }

    @GetMapping("/api/centralControl/menu/getCurrentUser")
    @Operation(summary = "获取当前登录用户菜单信息")
    public ResultResponse<GenerateListVo<MenuTreeRespVo>> getCurrentUser() {
        List<MenuTreeRespVo> currentMenuTree = menuService.getCurrentMenuTree();
        return ResultResponse.success(new GenerateListVo<>(currentMenuTree));
    }

    @GetMapping("/api/centralControl/menu/getList")
    @Operation(summary = "获取所有菜单信息")
    public ResultResponse<GenerateListVo<MenuTreeRespVo>> getList() {
        List<MenuTreeRespVo> list = menuService.getList();
        return ResultResponse.success(new GenerateListVo<>(list));
    }

}
